<?php $this->import('Header') ?>
<div class="row-fluid">
    <div style="margin: 5px;">
        <a href="javascript:;" onclick="history.go(-1);" class="btn">返回</a>
    </div>
    <div style="margin: 5px;">
        <?php if(!empty($articleInfo)){?>
            <div>
                <table class="table">
                    <tr>
                        <td>Id</td>
                        <td>文章名称</td>
                        <td>文章分类</td>
                        <td>文章状态</td>
                        <td>操作</td>
                    </tr>
                    <?php foreach ($articleInfo as $key => $val) : ?>
                        <tr>
                            <td><?php echo $val['Id'] ?></td>
                            <td><?php echo $val['Name'] ?></td>
                            <td><?php echo $val['CategoryName'] ?></td>
                            <td><?php echo $val['Status']?'有效':'无效'; ?></td>
                            <td>
                                <a href="/Article/Add?pid=<?php echo $pid;?>&id=<?php echo $val['Id'] ?>" class="btn">查看详情</a>
                                <a href="javascript:void(0)" onclick="del(<?php echo $val['Id'] ?>)" class="btn btn-primary">删除文章</a>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </table>
                <?php if (isset($pager)) {
                    \Controller\UC\Pager::instance()->run(array('pager' => $pager));
                } ?>
            </div>
        <?php }else{?>
            <?php echo '没有找到文章！'; }?>
    </div>
</div>
<?php $this->import('Footer') ?>

<script>

    function verification(obj){
        var name = $(obj).find('input[name="name"]').val();
        var title = $(obj).find('input[name="title"]').val();
        if(name=='' && title==''){
            alert('请输入文章名称或者标题！')
            return false;
        }
        return true;
    }

    function del(id){
        var r=confirm("是否删除这条数据？")
        if(r){
            $.ajax({
                url: '/Ajax/Article/del',
                type: 'post',
                dataType: 'json',
                data: {id:id},
                success: function(data) {
                    if (data.error) {
                        alert(data.data);
                    } else {
                        alert('文章删除成功！');
                        window.location.reload();
                    }
                }
            });
        }else{
            alert('你取消了删除操作！');
        }
    }
</script>